// src/api/merchant.js
import request from '@/utils/request'



/**
 * 审核商户资质
 * @param {{ userId: number, auditStatus: 1|2, rejectReason?: string }} dto
 */
export const auditMerchant = dto =>
  request.put('/api/merchant-info/audit', dto)

export function getPendingMerchants() {
  return request.get('/api/merchant-info/pending')
}

export function getMerchantById(userId) {
  return request.get(`/api/merchant-info/${userId}`)
}

export const updateMerchantInfoService = (userId, shopName) => {
    return request({
        url: '/api/merchant-info/update',
        method: 'get',
        params : {userId, shopName}
    })
};

export const resetMerchantPasswordService = (userId, password, rePassword) => {
    return request({
        url: '/api/merchant-info/reset-password',
        method: 'get',
        params : {userId, password, rePassword}
    })
};

export const getMerchantOrdersService = (merchantId, page, size) => {
    return request({
        url: '/api/merchant-info/orders',
        method: 'get',
        params : {merchantId, page, size}
    })
};


export const shipOrderService = (data) => {
    return request({
        url: '/api/merchant-info/ship-order',
        method: 'post',
        data
    })
};

export const getProductsService = (merchantId, page, size) => {
    return request({
        url: '/api/merchant-info/products',
        method: 'get',
        params : { merchantId, page, size }
    })
};

export const createProductService = (data) => {
    return request({
        url: '/api/merchant-info/product',
        method: 'post',
        data
    })
};


export const updateProductService = (data) => {
    return request({
        url: '/api/merchant-info/product',
        method: 'put',
        data
    })
};

export const toggleProductStatusService = (spuId, status) => {
    return request({
        url: '/api/merchant-info/product/changeStatus',
        method: 'put',
        params: {spuId, status}
    })
};

export const getPromotionsService = () => {
    return request({
        url: '/api/merchant-info/promotions',
        method: 'get',
    })
};

export const getSkusService = (id) => {
    return request({
        url: '/api/merchant-info/skus',
        method: 'get',
        params: {id}
    })
};

export const getSkusServiceByAd = () => {
    return request({
        url: '/api/merchant-info/skusByAd',
        method: 'get'
    })
};


export const addSeckillItemService = (data) => {
    return request({
        url: '/api/merchant-info/seckill-items',
        method: 'post',
        data
    })
};


export const addGroupbuyItemService = (data) => {
    return request({
        url: '/api/merchant-info/groupbuy-item',
        method: 'post',
        data
    })
};

export const addFullReductionItemService = (data) => {
    return request({
        url: '/api/merchant-info/full-reduction-item',
        method: 'post',
        data
    })
};

export const addComboItemService = (activityId, skuId) => {
   return request({
        url: '/api/merchant-info/combo-item',
        method: 'post',
        params: {activityId, skuId}
    })
};


export const getPromotionItemsService = (activityId, type) => {
    return request({
        url: '/api/merchant-info/promotion-items',
        method: 'get',
        params: {activityId, type}
    })
};

export const deletePromotionItemService = (activityId, skuId, type) => {
    return request({
        url: '/api/merchant-info/promotion-item',
        method: 'delete',
        params: {activityId, skuId, type}
    })
};

export const updateConfigService = (data) =>{
    return request({
        url: '/api/merchant-info/promotion/config',
        method: 'put',
        data
    })
}


export const getRefundsService = async ( page, size, merchantId ) => {
    return request({
        url: '/api/refund-record/refunds',
        method: 'get',
        params: { page, size, merchantId }
    })
}

export const approveRefundService = async (paymentId, refundSn, merchantId) => {
    return request({
        url: '/api/refund-record/refunds/approve',
        method: 'post',
        params: { paymentId, refundSn, merchantId }
    })
}

export const rejectRefundService = async (paymentId, refundSn, merchantId) => {
    return request({
        url: '/api/refund-record/refunds/reject',
        method: 'post',
        params: { paymentId, refundSn, merchantId }
    })
}

export const getEvaluationsService = async (page, size, merchantId) => {
    return request({
        url: '/api/evaluation/evaluations',
        method: 'get',
        params: { page, size, merchantId }
    })
}